package com.echo.code.demo;

import lombok.extern.log4j.Log4j2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by baiyp on 2019/05/18.
 */
@WebServlet(name = "error", urlPatterns = "/error", initParams = {@WebInitParam(name = "language", value = "english")})
@Log4j2
public class ErrorServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            doSomething();
        } catch (IOException e) {
            // throw e;
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
        //resp.sendRedirect(req.getServletContext().getContextPath() + "/index.jsp");
    }

    public void doSomething() throws IOException {
        throw new IOException("io error");
    }
}
